<template>
    <div class="m-content" style="padding: 0px;">
        <div class="alert alert-custom alert-default" role="alert">
            <div class="alert-icon">
                <span class="svg-icon svg-icon-primary svg-icon-xl">
                    <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="24px"
                        height="24px" viewBox="0 0 24 24" version="1.1">
                        <g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
                            <rect x="0" y="0" width="24" height="24"></rect>
                            <path d="M7.07744993,12.3040451 C7.72444571,13.0716094 8.54044565,13.6920474 9.46808594,14.1079953 L5,23 L4.5,18 L7.07744993,12.3040451 Z M14.5865511,14.2597864 C15.5319561,13.9019016 16.375416,13.3366121 17.0614026,12.6194459 L19.5,
                                18 L19,23 L14.5865511,14.2597864 Z M12,3.55271368e-14 C12.8284271,3.53749572e-14 13.5,0.671572875 13.5,1.5 L13.5,
                                4 L10.5,4 L10.5,1.5 C10.5,0.671572875 11.1715729,3.56793164e-14 12,3.55271368e-14 Z"
                                fill="#000000" opacity="0.3"></path>
                            <path
                                d="M12,10 C13.1045695,10 14,9.1045695 14,8 C14,6.8954305 13.1045695,6 12,6 C10.8954305,6 10,6.8954305 10,8 C10,9.1045695 10.8954305,
                                10 12,10 Z M12,13 C9.23857625,13 7,10.7614237 7,8 C7,5.23857625 9.23857625,3 12,3 C14.7614237,3 17,5.23857625 17,8 C17,10.7614237 14.7614237,13 12,13 Z"
                                fill="#000000" fill-rule="nonzero"></path>
                        </g>
                    </svg>
                </span>
            </div>
            <div class="alert-text">
                说明：
                <br>卸载模块范围仅限于删除授权中心模块中配置内数据：
                <br>
                <code>如密钥，账号类型，资源菜单，资源功能，角色，角色人员，角色资源，子系统</code>等使得配置类数据干净. 
            </div>
        </div>
        <div class="m-portlet  m-portlet--unair">
            <div class="m-portlet__body  m-portlet__body--no-padding">              
                <div class="row m-row--no-padding m-row--col-separator-xl" v-for="item in dataList" :key="item.index">
                    <div class="col-md-12 col-lg-6 col-xl-3" v-for="subItem in item" :key="subItem.keyInfoId" >
                        <div class="m-widget24">
                            <div class="m-widget24__item">
                                <h4 class="m-widget24__title"><i :class="subItem.icon"></i>{{ subItem.name }}</h4>                                
                                <span class="m-widget24__desc" v-if="subItem.createTime != '' && subItem.createTime != null">{{ subItem.createTime }}</span>
                                <span class="m-widget24__desc" v-else>暂无 </span>                               
                                <span class="m-widget24__stats m--font-brand" style="cursor: pointer;" @click="deleteModule(subItem)"><i class="la la-remove"></i></span>
                            </div>
                        </div>
                        <br>
                    </div>
                </div>
            </div>

        </div>
    </div>
</template>


<script>
import { SET_BREADCRUMB } from "@/store/breadcrumbs.module";
import Swal from "sweetalert2";
import apiUtil from "@/core/util/apiUtil.js";
import { handleNotify, handleAlert, handleConfirm, showWating, closeWating ,chunkArray} from "@/core/util/jehcUtil.js";
export default {
    data() {
        return {
            searchForm: {},
            dataList: [],
            sels: [], //当前选框选中的值
            pageNo: 1,      // 默认当前是第一页
            pageSize: 5,    // 当前每页的数据是5条
            totalCount: 0   // 总数默认为0
        }
    },
    components: {
    },
    mounted() {
        this.$store.dispatch(SET_BREADCRUMB, [{ title: "模块卸载" }]);
        this.initList();   // 按当前的页号和每页的数据量进行查询
    },
    methods: {        
        initList() {
            let params = {};
            apiUtil.query(process.env.VUE_APP_OAUTH_API + "/oauthSysMode/listAll", params).then(({ data }) => {
                let dataArray = data.data;
                let newArray = chunkArray(dataArray,4);
                this.dataList = newArray;
                console.log(this.dataList);
            });
        },
        deleteModule(subItem){
            this.$confirm('确定要卸载：'+subItem.name+'模块？', "提示", {type: "warning",}).then(() => {
                var params = { id: subItem.id };               
                apiUtil.delete(process.env.VUE_APP_OAUTH_API + '/oauth/uninstall', params).then(data => {
                    if (data.data.success) {
                        handleAlert("卸载成功", "success", 3);
                        this.initList();
                    } else {
                        handleAlert("卸载失败", "error", 3);
                    }
                });
            }).catch(() => { });//注意这里，这里是重点！！！;
        }
    }
};
</script>